﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;

namespace DDOS
{
 
    class SoundManager
    {
        private static SoundManager instance;
        public static SoundManager Instance { get { return instance; } }

        private SoundEffect logon;
        public SoundEffect Logon { get { return logon; } }

        private SoundEffectInstance logoninstance;
        public SoundEffectInstance LogonInstance { get { return logoninstance; } }

        private Song menusong;
        public Song MenuSang { get { return menusong; } }

        private Song ingame;
        public Song InGame { get { return ingame; } }

        private Song boss1;
        public Song Boss1 { get { return boss1; } }

        private Song boss2;
        public Song Boss2 { get { return boss2; } }

        private SoundEffect crunch;
        public SoundEffect Crunch { get { return crunch; } }

        private SoundEffectInstance crunchinstance;
        public SoundEffectInstance CrunchInstance { get { return crunchinstance; } }

        public static void Initialize(Game game)
        {
            instance = new SoundManager();
            instance.logon = game.Content.Load<SoundEffect>("Sounds/terminal_main_hacked");
            instance.menusong = game.Content.Load<Song>("Sounds/Menu_Overload_Loop");
            instance.ingame = game.Content.Load<Song>("Sounds/InGame");
            instance.boss1 = game.Content.Load<Song>("Sounds/Boss Overload 1");
            instance.boss2 = game.Content.Load<Song>("Sounds/Boss Overload 2");
            instance.logoninstance = instance.logon.CreateInstance();
            instance.crunch = game.Content.Load<SoundEffect>("Sounds/crunch");
            instance.crunchinstance = instance.crunch.CreateInstance();
        }

        public void Volumn(float v)
        {
            MediaPlayer.Volume = v;
        }

        public void Play(Song song, bool repeat)
        {
            if (repeat)
            {
                MediaPlayer.IsRepeating = true;
            }
            else
            {
                MediaPlayer.IsRepeating = false;
            }

            if (MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.Play(song);
            }
        }
        


        public void Pause()
        {
            if (MediaPlayer.State == MediaState.Playing)
            {
                MediaPlayer.Pause();
            }
        }
        public void Resume()
        {
            if (MediaPlayer.State == MediaState.Paused)
            {
                MediaPlayer.Resume();
            }
        }


        public void Stop()
        {
            MediaPlayer.Stop();
            MediaPlayer.IsRepeating = true;
        }

    }
}
